#!/bin/sh -e

pio_to_sram=0x2000
sram_to_pio=0x2004

if [ -f fel-pio.bin ]; then
	./fel write 0x2000 fel-pio.bin
else
	./fel write 0x2000 bin/fel-pio.bin
fi

./fel exec $pio_to_sram
./fel read 0x3000 0x228 pio.reg
./pio -i pio.reg print > pio.old
cat pio.old | fgrep -v '<0><0><0><0>'

while read cmd; do
	./pio -i pio.reg -o pio.reg $cmd
	./fel write 0x3000 pio.reg
	./fel exe 0x2004
	./fel exe 0x2000
	./fel read 0x3000 0x228 pio.reg
	./pio -i pio.reg print > pio.new
	diff -U0 pio.old pio.new || true
	mv -f pio.new pio.old
done
